-- @owner: cr13
-- @date: 2025/3/27
-- @testpoint:重建后的函数和原有函数风格不同，部分合理报错
--step1: 创建 PostgreSQL 风格的自定义函数;expect:成功
drop function if exists add_numbers_pg(a int,b int);
CREATE FUNCTION add_numbers_pg(a INTEGER, b INTEGER)
RETURNS INTEGER AS $$
BEGIN
RETURN a + b;
END;
$$ LANGUAGE plpgsql;
--step2: 创建视图;expect:成功
drop view if exists v_ddl0043;
create view v_ddl0043 as select add_numbers_pg(1,2);
--step3: 查询视图;expect:成功
select * from v_ddl0043;
--step4: 删除函数;expect:成功
drop function if exists add_numbers_pg(a INTEGER, b INTEGER) restrict;
--step5: 创建 Oracle 风格的自定义函数;expect:成功
CREATE FUNCTION add_numbers_pg(a INTEGER, b INTEGER)
RETURN INTEGER AS
result INTEGER;
BEGIN
result := a + b;
RETURN result;
END;
/
--step6: 查询视图状态;expect:无效
select valid from pg_object where object_oid='v_ddl0043'::regclass;
--step7: 查询视图数据;expect:成功
select * from v_ddl0043;
--step8: 查询视图定义;expect:成功
select pg_get_viewdef('v_ddl0043');
--step9: 查询视图状态;expect:有效
select valid from pg_object where object_oid='v_ddl0043'::regclass;
--step10: 清理环境
drop function if exists add_numbers_pg;
drop view if exists v_ddl0043;
